interface LoginObj {
  id: number,
  userName: string, 
  name: string,
  roleId: number, 
  roleName: string,
  phoneNum: string, 
  avatar: string, 
  departmentId:number, 
  departmentName: string,
  email: string,
  status: number,
  roleList?: any
}

export default {
  state: {
    id: null,
    userName: '', 
    name:'',
    roleId: null, 
    roleName: '',
    phoneNum: '', 
    avatar: '', 
    departmentId:null, 
    departmentName: '',
    email:'',
    status: null,
    roleList: null
  },
  mutations: {
    SET_ID (state:any, id:number) {
      state.id = id
    },
    SET_USERNAME (state:any, userName:string) {
      state.userName = userName
    },
    SET_NAME (state:any, name:string) {
      state.name = name
    },
    SET_ROLEID (state:any, roleId:number) {
      state.roleId = roleId
    },
    SET_ROLENAME (state:any, roleName:string) {
      state.roleName = roleName
    },
    SET_PHONENUM (state:any, phoneNum:string) {
      state.phoneNum = phoneNum
    },
    SET_AVATAR (state:any, avatar:string) {
      state.avatar = avatar
    },
    SET_DEPARTMENTID (state:any, departmentId:number) {
      state.departmentId = departmentId
    },
    SET_DEPARTMENTNAME (state:any, departmentName:string) {
      state.departmentName = departmentName
    },
    SET_EMAIL (state:any, email:string) {
      state.email = email
    },
    SET_STATE (state:any, status:number) {
      state.status = status
    },
    SET_ROLELIST (state:any, roleList:any) {
      state.roleList = roleList
    },
    SET_USER_INFO (state:any, obj:LoginObj) {
      state.id = obj ? obj.id : null;
      state.userName = obj ? obj.userName : '';
      state.name = obj ? obj.name : '';
      state.roleId = obj ? obj.roleId : null;
      state.roleName = obj ? obj.roleName : '';
      state.phoneNum = obj ? obj.phoneNum : '';
      state.avatar = obj ? obj.avatar : '';
      state.departmentId = obj ? obj.departmentId : '';
      state.departmentName = obj ? obj.departmentName : '';
      state.email = obj ? obj.email : '';
      state.status = obj ? obj.status : null;
      state.roleList = obj ? obj.roleList : null;
    }
  },
  actions: {
    SET_USERNAME (context:any, userName:string) {
      context.commit('SET_USERNAME', userName)
    },
    async LOGIN (context:any, loginObj:LoginObj) {
      context.commit('SET_USER_INFO', loginObj)
    },
    async LOGOUT(context:any) {
      context.commit('SET_USER_INFO', null)
    }
  }
}